package demo03;

import java.util.ArrayList;
import java.util.Collections;

/*
    - java.utils.Collections是集合工具类，用来对集合进行操作。部分方法如下：
        public static <T> void sort(List<T> list):将集合中元素按照默认规则排序。

    注意:
         sort(List<T> list)使用前提
         被排序的集合里边存储的元素,必须实现Comparable,重写接口中的方法compareTo定义排序的规则

    Comparable接口的排序规则:
        自己(this)-参数:升序
 */
public class Demo02Sort1 {
    public static void main(String[] args) {
        ArrayList<Integer>arrayList1=new ArrayList<>();
        Collections.addAll(arrayList1,6,5,4,8,2,3,4);
        System.out.println(arrayList1);//[6, 5, 4, 8, 2, 3, 4]
        Collections.sort(arrayList1);
        System.out.println(arrayList1);//[2, 3, 4, 4, 5, 6, 8]
        ArrayList<String>arrayList2=new ArrayList<>();
        Collections.addAll(arrayList2,"abc","abd","b");
        Collections.sort(arrayList2);
        System.out.println(arrayList2);//[abc, abd, b]

        ArrayList<Person>personArrayList=new ArrayList<>();
        Collections.addAll(personArrayList,new Person("张三",18),new Person("李四",19),
                new Person("王五",15));
        System.out.println(personArrayList);
        Collections.sort(personArrayList);
        System.out.println(personArrayList);


    }
}
